<%--
  Created by IntelliJ IDEA.
  User: shen
  Date: 2020/5/11
  Time: 16:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>自主评分</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <%@include file="../common_resource.jsp" %>
<style>
    body{
        font-size: 15px;
    }
</style>
    <script>

        $(function () {
            $('.score').each(function (index,domfile) {
                console.log($(domfile).text())
                for (var i = 0; i <=index ; i++) {
                    /* 评分下拉列表*/
                    var judgeScore = $('.judgeScore');
                    for (var j = 0; j <=($(domfile).text()); j++) {
                        judgeScore.append('<option value="' + j +'">'+ j + '</option>');
                    }
                }

                })


            })

$(function () {
    $('.shScore').each(function (index,domfile) {
        console.log($(domfile).text())
        for (var k = 0; k <=index ; k++) {
            /* 评分下拉列表*/
            var shJudgeScore = $('.shJudgeScore');
            for (var l = 0; l <=($(domfile).text()); l++) {
                shJudgeScore.append('<option value="' + l +'">'+ l + '</option>');
            }
            shJudgeScore.clear();

        }
    })
})

        function to(){
            location.href="views/question/single_input.jsp";
        }
        function checkAll(){
            var box=document.getElementsByName("selectID");
            var chkall=document.getElementById("checkall");
            if(chkall.checked){
                for(var i=0;i<box.length;i++){
                    box[i].checked=true;
                }
            }else{
                for(var i=0;i<box.length;i++){
                    box[i].checked=false;
                }
            }
        }
        function detail(id){
            var o = document.getElementById("option"+id);
            if (o){
                if (o.style.display == "none"){ o.style.display = "block"; } else {o.style.display = "none";}
            }


            $.get("question/selectQuestionById.do",{"id":id},function(json){
                $.each(json, function(i,item){
                    $("#optionA"+id).html(item.optionA);
                    $("#optionB"+id).html(item.optionB);
                    $("#optionC"+id).html(item.optionC);
                    $("#optionD"+id).html(item.optionD);
                });

            });
        }


        function collapseExpand(ss){
            $(ss).style.display = "block";
        }


        function openOption(){
            var obj=document.getElementsByName('selectID');
            for(var i=0; i<obj.length; i++){
                var id=obj[i].value;
                $.get("question/selectQuestionById.do",{"id":id},function(json){
                    $.each(json, function(i,item){
                        $("#optionA"+item.questionId).html(item.optionA);
                        $("#optionB"+item.questionId).html(item.optionB);
                        $("#optionC"+item.questionId).html(item.optionC);
                        $("#optionD"+item.questionId).html(item.optionD);
                        $("#optionE"+item.questionId).html(item.optionE);
                    });
                });
                var o = document.getElementById("option"+id);
                if (o){
                    if (o.style.display == "none"){ o.style.display = "block";$("#openlog").html("[-]"); } else {o.style.display = "none"; $("#openlog").html("[+]");}
                }
            }

        }
        $(function(){
            <c:if test="${not empty updateRdiolag and updateRdiolag}">
            $("#successModal").modal();
            </c:if>

            <c:if test="${not empty updateRdiolag and (not updateRdiolag)}">
            $("#feildModal").modal();
            </c:if>

            <c:if test="${not empty savaRdiolag and savaRdiolag}">
            $("#insertSuccessModal").modal();
            </c:if>

            <c:if test="${not empty savaRdiolag and (not savaRdiolag)}">
            $("#insertFailModal").modal();
            </c:if>
        });
    </script>

</head>
<body class="main_body" onload="opener.location.reload()">
<div class="container container-1180" >
    <div class="col" style="margin-top: 10px;">
        <div class="panel panel-info">
            <div class="panel-heading">
                <span ><i class="fa fa-user"></i></span> <label><font style="font-weight: bold;margin-left: 10px;">主观题评分</font></label>
                <label style="float: right;">

                    <div class="button_bar">
                        <button class="btn btn-info btn-sm" id="submitGrade" onclick="submitGrade('${rUnit.eId}')">提交评分</button>
                    </div>
                </label>
            </div>

            <form id="searchForm" name="searchForm" role="form"   action="testPaper/test" method="post">
                <!-- 试题类型 -->
                <!-- 查询 -->
                <input type="hidden" name="coll_exp" value="0" />
                <table border="0" width="100%" >

                    <tr>
                        <td >
                            <!-- 列表 -->
                            <div class="listDiv" id="allExam">
                                <%--试卷信息--%>
                                <c:forEach var="rUnit" items="${sessionScope.resultUnit}" varStatus="status">
                                    <div class="paner-body panel-heading tempExam" >
                                        <label style="color: black;">&nbsp;</label>

                                        试卷编号：<a id="resultUnit" href="">${rUnit.eId}</a>&nbsp;&nbsp;&nbsp;试卷总分：${rUnit.totalScore}&nbsp;&nbsp;&nbsp;试卷难度：${rUnit.difficultyLevel}&nbsp;&nbsp;&nbsp; 客观题得分：${sessionScope.sdExamAnswer[0].examination.totalScores}
                                    </div>
                                    <input type="hidden" id="totalScores" value="${sessionScope.sdExamAnswer[0].examination.totalScores}">
                                </c:forEach>

                                    <%--设置变量--%>
                                    <c:set var="index" value="${1}"/>
                                    <c:if test="${sessionScope.sdExamAnswer[0].sQuestion.sQuestionID ne null}">
                                    <label style="color: black;">单选题：&nbsp;</label>
                                     </c:if>
                                    <%--单选题--%>
                                <c:forEach var="sQlist" items="${sessionScope.sdExamAnswer}"  varStatus="status" >
                                <c:if test="${sQlist.sdfsQuestions.questionType ==1}">
                                    <div id="question${sQlist.sQuestion.sQuestionID }" class="panel panel-info sExamList" style="font-size: 14px;">
                                    <div class="paner-body panel-heading" >
                                        <label style="color: black;">&nbsp;</label>
                                        <a id="mir" onclick="addErrorQuestion('${sQlist.sQuestion.sQuestionID}','${sessionScope.loginUser.sstsUserID}')">
                                            <span id="sctxt${sQlist.sQuestion.sQuestionID}" class="glyphicon glyphicon-star-empty" ></span>
                                        </a>
                                            ${index}.<a href="javascript:detail(${sQlist.sQuestion.sQuestionID });">${sQlist.sdfsQuestions.question}(${sQlist.value}分)</a>

                                    </div>
                                    <div id="option${sQlist.sQuestion.sQuestionID}" class="radio_list_options panel-collapse collapse" style="display: inline-block">
                                        <ul style="margin-left:7px;">
                                            <li><span id="optionA${sQlist.sQuestion.sQuestionID}">${sQlist.sQuestion.optionA}</span></li>
                                            <li><span id="optionB${sQlist.sQuestion.sQuestionID}">${sQlist.sQuestion.optionB}</span></li>
                                            <li><span id="optionC${sQlist.sQuestion.sQuestionID}">${sQlist.sQuestion.optionC}</span></li>
                                            <li><span id="optionD${sQlist.sQuestion.sQuestionID}">${sQlist.sQuestion.optionD}</span></li>
                                            <c:if test="${not empty sQlist.sQuestion.optionE}">
                                                <li><span id="optionE${sQlist.sQuestion.sQuestionID}">${sQlist.sQuestion.optionE}</span></li>
                                            </c:if>

                                        </ul>

                                        <span class="answer1"style="color:red;font-size: 15px;font-weight: bold">参考答案：${sQlist.sQuestion.sCorrect } &nbsp;&nbsp;&nbsp;你的答案：${sQlist.sdAnswer}&nbsp;&nbsp;&nbsp; 得分：${sQlist.sdScore}

                                    </div>
                                </div>
                                     <div style="height: 10px"></div>
                                        <c:set var="index" value="${index+1}"/>
                                </c:if>
                                </c:forEach>

                                    <c:set var="index" value="${1}"/>
                                    <c:if test="${sessionScope.sdExamAnswer[0] ne null}">
                                    <label style="color: black;">判断题：&nbsp;</label>
                                    </c:if>
                                <%--判断题--%>
                                <c:forEach var="dQlist" items="${sessionScope.sdExamAnswer}"  varStatus="status">
                                    <c:if test="${dQlist.sdfsQuestions.questionType ==2}">
                                        <div id="question${dQlist.dQuestion.dQuestionID}" class="panel panel-info dExamList" style="font-size: 14px;">
                                        <div class="paner-body panel-heading">
                                             <label style="color: black;">&nbsp;</label>
                                            <a onclick="addErrorQuestion('${dQlist.dQuestion.dQuestionID}')">
                                                <span id="sctxt${dQlist.dQuestion.dQuestionID}"  class="glyphicon glyphicon-star-empty" style="padding: 0px"></span><i class="iconfont icon-favorite"></i>
                                            </a>
                                            ${index}.<a href="javascript:detail(${dQlist.dQuestion.dQuestionID});">${dQlist.sdfsQuestions.question}(${dQlist.value}分)</a>
                                        </div>
                                        <div id="option${dQlist.dQuestion.dQuestionID}" class="radio_list_options panel-collapse collapse" style="display: inline-block">
                                            <ul style="margin-left:7px;">
                                                <li><input type="radio" id="T${dQlist.dQuestion.dQuestionID}">T</li>
                                                <li><input type="radio" id="F${dQlist.dQuestion.dQuestionID}">F</li>
                                            </ul>

                                            <input type="hidden" name="fCorrect" value="${dQlist.dQuestion.dCorrect}">
                                    </div>
                                </div>
                                    <span class="answer1"style="color:red;font-size: 15px;font-weight: bold">参考答案：${dQlist.dQuestion.dCorrect } &nbsp;&nbsp;&nbsp;你的答案：${dQlist.sdAnswer}&nbsp;&nbsp;&nbsp; 得分：${dQlist.sdScore}</span>

                                    <div style="height: 10px"></div>
                                        <c:set var="index" value="${index+1}"/>
                                </c:if>
                                </c:forEach>
                                    <%--填空题--%>
                                    <c:set var="index" value="${1}"/>
                                    <c:if test="${sessionScope.fsExamAnswer[0].fQuestion.fQuestionID != null}">
                                    <label style="color: black;">填空题：&nbsp;</label>
                                    </c:if>
                                <c:forEach var="fQlist" items="${sessionScope.fsExamAnswer}" varStatus="status" begin="0" step="1">
                                        <c:if test="${fQlist.sdfsQuestions.questionType ==3}">
                                     <div id="question${fQlist.fQuestion.fQuestionID }" class="panel panel-info fExamList" style="font-size: 14px;">
                                        <div class="paner-body panel-heading" >
                                            <label style="color: black;">&nbsp;</label>
                                            <a onclick="addErrorQuestion('${fQlist.fQuestion.fQuestionID}','${sessionScope.loginUser.sstsUserID}')">
                                                <span id="sctxt${fQlist.fQuestion.fQuestionID}"  class="glyphicon glyphicon-star-empty" style="padding: 0px"></span><i class="iconfont icon-favorite"></i>
                                            </a>
                                            ${index}.<a href="javascript:detail(${fQlist.fQuestion.fQuestionID });">${fQlist.sdfsQuestions.question }(${fQlist.totalValue}分)
                                        </a>
                                            <span class="score" hidden>${fQlist.totalValue}</span>
                                            &nbsp;&nbsp;&nbsp;<span class="answer1" style="font-size: 15px">评分：</span><select class="judgeScore" name="judgeScore">

                                        </select>

                                        </div>
                                        <div id="option${fQlist.fQuestion.fQuestionID}" class="file-list panel-collapse collapse" style="display: inline-block">

                                            <input type="hidden" name="fCorrect" value="${fQlist.fQuestion.fCorrect}">
                                            <span class="answer" style="font-size: 15px;font-weight: bold">参考答案：${fQlist.fQuestion.fCorrect} &nbsp;&nbsp;&nbsp;你的答案：${fQlist.fsAnswer}&nbsp;&nbsp;&nbsp;</span>
                                            <c:if test="${fQlist.fsImages ne null}">
                                                <img src="${fQlist.fsImages}"  >
                                            </c:if>
                                        </div>
                                    </div>

                                    <div style="height: 10px"></div>
                                        <c:set var="index" value="${index+1}"/>
                                </c:if>
                                </c:forEach>

                                    <%--简答综合题--%>
                                    <c:set var="index" value="${1}"/>
                                    <c:if test="${sessionScope.fsExamAnswer[0].shQuestion.shQuestionID ne null}">
                                    <label style="color: black;">简答综合题：&nbsp;</label>
                                    </c:if>
                                <c:forEach var="shQlist" items="${sessionScope.fsExamAnswer}" >
                                        <c:if test="${shQlist.sdfsQuestions.questionType ==4 or shQlist.sdfsQuestions.questionType ==5}">
                                        <div id="question${shQlist.shQuestion.shQuestionID}" class="panel panel-info shExamList" style="font-size: 14px;">
                                        <div class="paner-body panel-heading">
                                            <label style="color: black;">&nbsp;</label>
                                            <a onclick="addErrorQuestion('${shQlist.shQuestion.shQuestionID}','${sessionScope.loginUser.sstsUserID}')">
                                                <span id="sctxt${shQlist.shQuestion.shQuestionID}"  class="glyphicon glyphicon-star-empty" style="padding: 0px"></span><i class="iconfont icon-favorite"></i>
                                            </a>
                                            ${index}.<a id="questionBody" href="javascript:detail(${shQlist.shQuestion.shQuestionID});">${shQlist.sdfsQuestions.question}(${shQlist.totalValue}分)</a>
                                            <c:if test="${shQlist.shQuestion.shQuestionImage ne null}">
                                                <img id="images" src="images/upload/${shQlist.shQuestion.shQuestionImage}">
                                            </c:if>
                                            <span class="shScore" hidden>${shQlist.totalValue}</span>
                                            &nbsp;&nbsp;&nbsp;<span class="answer" style="font-size: 15px">评分：</span><select class="shJudgeScore" name="shJudgeScore">
                                        </select>
                                        </div>
                                            <p style="color: red;font-size: 15px;font-weight: bold">参考答案：</p>
                                            <span id="questionBody" class="answer1"style="color:red;font-size: 15px">${shQlist.shQuestion.shCorrect}</span><br/><br/>
                                            <p style="color: red;font-size: 15px;font-weight: bold">你的答案：</p>
                                            <span id="questionBody" class="answer1"style="color:red;font-size: 15px">${shQlist.fsAnswer}</span>
                                            <c:if test="${shQlist.fsImages ne null}">
                                                <img src="${shQlist.fsImages}" >
                                            </c:if>
                                            <br/>
                                    </div>

                                    <div style="height: 10px"></div>
                                        <c:set var="index" value="${index+1}"/>

                                </c:if>
                                </c:forEach>
                        </td>
                    </tr>
                </table>

            </form>
        </div>
    </div>
</div>


<script src="bootstrap/plugins/transition.js"></script>
<script src="bootstrap/plugins/modal.js"></script>
<script src="bootstrap/plugins/tooltip.js"></script>
<script src="bootstrap/plugins/popover.js"></script>
<script src="bootstrap/plugins/collapse.js"></script>
<script src="js/jquery-2.0.0.js"></script>
<script src="bootstrap/js/jquery.editable-select.min.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>

<script>
    //window.location.reload();
    $(function () {

        /*if (location.search.indexOf("?")==0 ){
            location.href+="?myurl";
        }else {
            if (location.search.indexOf("myurl")==0){
                location.href+="&myurl";
            }
        }*/
        /*if (location.href.indexOf("#reloaded")<=0){
            location.href=location.href+"#reloaded";*/
        if (location.href.indexOf("?reload=true")<=-1 ){
            location.href+="?reload=true";
            //location.reload();
            return false;
           /* location.reload();
            location.reload();
            location.reload();
            location.reload();
            location.reload();
            self.location.reload();*/
            //window.location.reload();
        }
    })
    //window.opener.document.location.reload();
    /*function fresh(){
        if (location.href.indexOf("?reload=true")<-1 ){
            location.href+="?reload=true";
        }

    }
    setTimeout("fresh()",100000000000);*/


/*
    location.reload();
*/
    //收藏操作 按钮被点击时执行
    function addErrorQuestion(qId) {
        var text = $("#sctxt"+qId);
        var classText = $(text).attr("class");
        var examNo = $('#resultUnit').text();
        console.log(classText)

        if (classText.includes("glyphicon-star-empty")){

            $.ajax({
                type:'post',
                url:'error/insertErrorQuestion',
                data:{examNo:  examNo,qId: qId},
                success:function(map){
                        if(map.insertErrorQuestion==1){
                            // 改变类样式
                            $(text).removeClass("glyphicon-star-empty");
                            $(text).addClass("glyphicon-star");
                        }else {
                            alert("error,收藏失败");
                        }
            },
                error:function(){
                    alert("error,收藏失败");
                }
        })
        }else if (classText.includes("glyphicon-star")) {
            $.ajax({
                type:'post',
                url:'error/deleteErrorQuestion',
                data:{examNo:  examNo,qId: qId},
                success:function(map){
                    if(map.deleteErrorQuestion==1){
                        // 改变类样式
                        $(text).removeClass("glyphicon-star");
                        $(text).addClass("glyphicon-star-empty");
                    }else {
                        alert("error,收藏失败");
                    }
                },
                error:function(){
                    alert("error,取消收藏失败");
                }
            })
        }

    }
// 提交评分
function submitGrade(examNo) {
    // 获取下拉列表
    fExamListAnswer = new Array();
    shExamListAnswer = new Array();
    //存放传给后台的所有数据
    resultMap={};

    var fExamList = $('.fExamList');
    var shExamList = $('.shExamList');
    var totalScores = $('#totalScores').val();
    // 先清空
    fExamListAnswer = [];
    shExamListAnswer = [];

    $('.fExamList>div option:selected').each(function (index,domfile) {
        fExamListAnswer.push($(domfile).val())
        console.log($(domfile).val())
    })
    $('.shExamList>div option:selected').each(function (index,domfile) {
        shExamListAnswer.push($(domfile).val())
        console.log($(domfile).val())
    })

    resultMap = {};

    resultMap["fExamList"]=fExamListAnswer;
    resultMap["shExamList"]=shExamListAnswer;
    resultMap["totalScores"]=totalScores;


    submitScore();
    var fsScore = examNo.options[ele.selectedIndex].value;
}
function submitScore() {
    var jsonData=JSON.stringify(resultMap);
    console.log(jsonData)

    $.ajax({
        url:'testPaper/updateExam',
        method:'post',
        contentType: "application/json; charset=utf-8",
        data:jsonData,
        success:function(data){
            //alert(data)
            if(data.updateExam!=0){
                //跳转测试页面
                location.href="views/exam/selectTest.jsp"
            }
        },
        error:function(){
            alert("error");
        }
    })


}



</script>
</body>
</html>


